<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform @deleteItem="deleteUserItem" ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '@/static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr,errorModal} from '@/static/js/common.js';
	import urlUtil from '@/static/js/urlUtil.js'
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				newProductIdCacheKey: 'qam-cgjy-incomingInspectionReport-title3-newProductIdCacheKey',
				actualSample: -1,
			})
		},
		methods:{
			initLoad(){
				let _that = this
				let pro1 = _that.om.request('dictSource/loadCombo', { sourceId: 283,categoryId: 6175 });
				Promise.all([pro1]).then(res=>{
					_that.$refs.autoform.changeEditor("title4", "sample1ResultId", "data", configSelectData(res[0],"id","text"))
					_that.$refs.autoform.initSelectIndex("title4", "sample1ResultId")
					_that.$refs.autoform.changeEditor("title4", "sample2ResultId", "data", configSelectData(res[0],"id","text"))
					_that.$refs.autoform.initSelectIndex("title4", "sample2ResultId")
					_that.$refs.autoform.changeEditor("title4", "sample3ResultId", "data", configSelectData(res[0],"id","text"))
					_that.$refs.autoform.initSelectIndex("title4", "sample3ResultId")
					_that.$refs.autoform.changeEditor("title4", "sample4ResultId", "data", configSelectData(res[0],"id","text"))
					_that.$refs.autoform.initSelectIndex("title4", "sample4ResultId")
					_that.$refs.autoform.changeEditor("title4", "sample5ResultId", "data", configSelectData(res[0],"id","text"))
					_that.$refs.autoform.initSelectIndex("title4", "sample5ResultId")
					_that.$nextTick(function(){
						if(!_that.$refs.autoform.formdata.projectId){
							_that.$refs.autoform.changeEditor("title4","sample1ResultId","type","selectbox")
							_that.$refs.autoform.changeEditor("title4","sample2ResultId","type","selectbox")
							_that.$refs.autoform.changeEditor("title4","sample3ResultId","type","selectbox")
							_that.$refs.autoform.changeEditor("title4","sample4ResultId","type","selectbox")
							_that.$refs.autoform.changeEditor("title4","sample5ResultId","type","selectbox")
						}
						
						if(_that.$refs.autoform.formdata.projectTypeId == 7173){
							_that.$refs.autoform.changeEditor("title4","sample1ActualNum","type","numberbox")
							_that.$refs.autoform.changeEditor("title4","sample2ActualNum","type","numberbox")
							_that.$refs.autoform.changeEditor("title4","sample3ActualNum","type","numberbox")
							_that.$refs.autoform.changeEditor("title4","sample4ActualNum","type","numberbox")
							_that.$refs.autoform.changeEditor("title4","sample5ActualNum","type","numberbox")
							_that.$refs.autoform.changeEditor("title4","sample1ResultId","type","labelbox")
							_that.$refs.autoform.changeEditor("title4","sample2ResultId","type","labelbox")
							_that.$refs.autoform.changeEditor("title4","sample3ResultId","type","labelbox")
							_that.$refs.autoform.changeEditor("title4","sample4ResultId","type","labelbox")
							_that.$refs.autoform.changeEditor("title4","sample5ResultId","type","labelbox")
						}else{
							_that.$refs.autoform.changeEditor("title4","sample1ActualNum","type","labelbox")
							_that.$refs.autoform.changeEditor("title4","sample2ActualNum","type","labelbox")
							_that.$refs.autoform.changeEditor("title4","sample3ActualNum","type","labelbox")
							_that.$refs.autoform.changeEditor("title4","sample4ActualNum","type","labelbox")
							_that.$refs.autoform.changeEditor("title4","sample5ActualNum","type","labelbox")
							_that.$refs.autoform.changeEditor("title4","sample1ResultId","type","selectbox")
							_that.$refs.autoform.changeEditor("title4","sample2ResultId","type","selectbox")
							_that.$refs.autoform.changeEditor("title4","sample3ResultId","type","selectbox")
							_that.$refs.autoform.changeEditor("title4","sample4ResultId","type","selectbox")
							_that.$refs.autoform.changeEditor("title4","sample5ResultId","type","selectbox")
						}
					})
				})
			},
			inputSample1ActualNum(num){
				if(num){
					this.inputSampleActualNumChange(num, 1)
				}else{
					this.$refs.autoform.clear('title4', 'sample1ActualNum')
				}
			},
			inputSample2ActualNum(num){
				if(num){
					this.inputSampleActualNumChange(num, 2)
				}else{
					this.$refs.autoform.clear('title4', 'sample2ActualNum')
				}
			},
			inputSample3ActualNum(num){
				if(num){
					this.inputSampleActualNumChange(num, 3)
				}else{
					this.$refs.autoform.clear('title4', 'sample3ActualNum')
				}
			},
			inputSample4ActualNum(num){
				if(num){
					this.inputSampleActualNumChange(num, 4)
				}else{
					this.$refs.autoform.clear('title4', 'sample4ActualNum')
				}
			},
			inputSample5ActualNum(num){
				if(num){
					this.inputSampleActualNumChange(num, 5)
				}else{
					this.$refs.autoform.clear('title4', 'sample5ActualNum')
				}
			},
			inputSampleActualNumChange(num, index){
				let _that = this
				num = parseFloat(num)
				let vnum = 0;
				let sampleResultId = '';
				let sampleResultName = '';
				let sampleUnqualifiedTypeId = '';
				let sampleUnqualifiedTypeName = '';

				if(num<_that.$refs.autoform.formdata.minimum || num>_that.$refs.autoform.formdata.maximum){
					sampleResultId = '6226'
					sampleResultName = '不合格'
					sampleUnqualifiedTypeId = _that.$refs.autoform.formdata.nonConformanceCategoryId
					sampleUnqualifiedTypeName = _that.$refs.autoform.formdata.nonConformanceCategoryName	
				}else{
					sampleResultId = '6227'
					sampleResultName = '合格'
				}
					
				if(index == 1){
					_that.$refs.autoform.formdata.sample1ActualNum = num
					_that.$refs.autoform.formdata.sample1ResultId = sampleResultId
					_that.$refs.autoform.formdata.sample1ResultName = sampleResultName
					_that.$refs.autoform.formdata.sample1UnqualifiedTypeId = sampleUnqualifiedTypeId
					_that.$refs.autoform.formdata.sample1UnqualifiedTypeName = sampleUnqualifiedTypeName
				}else if(index == 2){
					_that.$refs.autoform.formdata.sample2ActualNum = num
					_that.$refs.autoform.formdata.sample2ResultId = sampleResultId
					_that.$refs.autoform.formdata.sample2ResultName = sampleResultName
					_that.$refs.autoform.formdata.sample2UnqualifiedTypeId = sampleUnqualifiedTypeId
					_that.$refs.autoform.formdata.sample2UnqualifiedTypeName = sampleUnqualifiedTypeName
				}else if(index == 3){
					_that.$refs.autoform.formdata.sample3ActualNum = num
					_that.$refs.autoform.formdata.sample3ResultId = sampleResultId
					_that.$refs.autoform.formdata.sample3ResultName = sampleResultName
					_that.$refs.autoform.formdata.sample3UnqualifiedTypeId = sampleUnqualifiedTypeId
					_that.$refs.autoform.formdata.sample3UnqualifiedTypeName = sampleUnqualifiedTypeName
				}else if(index == 4){
					_that.$refs.autoform.formdata.sample4ActualNum = num
					_that.$refs.autoform.formdata.sample4ResultId = sampleResultId
					_that.$refs.autoform.formdata.sample4ResultName = sampleResultName
					_that.$refs.autoform.formdata.sample4UnqualifiedTypeId = sampleUnqualifiedTypeId
					_that.$refs.autoform.formdata.sample4UnqualifiedTypeName = sampleUnqualifiedTypeName
				}else{
					_that.$refs.autoform.formdata.sample5ActualNum = num
					_that.$refs.autoform.formdata.sample5ResultId = sampleResultId
					_that.$refs.autoform.formdata.sample5ResultName = sampleResultName
					_that.$refs.autoform.formdata.sample5UnqualifiedTypeId = sampleUnqualifiedTypeId
					_that.$refs.autoform.formdata.sample5UnqualifiedTypeName = sampleUnqualifiedTypeName
				}
			},
			clearSample1ActualNum(){
				this.$refs.autoform.clear('title4', 'sample1ActualNum')
				this.$refs.autoform.clear('title4', 'sample1ResultId')
				this.$refs.autoform.clear('title4', 'sample1UnqualifiedTypeId')
			},
			clearSample2ActualNum(){
				this.$refs.autoform.clear('title4', 'sample2ActualNum')
				this.$refs.autoform.clear('title4', 'sample2ResultId')
				this.$refs.autoform.clear('title4', 'sample2UnqualifiedTypeId')
			},
			clearSample3ActualNum(){
				this.$refs.autoform.clear('title4', 'sample3ActualNum')
				this.$refs.autoform.clear('title4', 'sample3ResultId')
				this.$refs.autoform.clear('title4', 'sample3UnqualifiedTypeId')
			},
			clearSample4ActualNum(){
				this.$refs.autoform.clear('title4', 'sample4ActualNum')
				this.$refs.autoform.clear('title4', 'sample4ResultId')
				this.$refs.autoform.clear('title4', 'sample4UnqualifiedTypeId')
			},
			clearSample5ActualNum(){
				this.$refs.autoform.clear('title4', 'sample5ActualNum')
				this.$refs.autoform.clear('title4', 'sample5ResultId')
				this.$refs.autoform.clear('title4', 'sample5UnqualifiedTypeId')
			},
			inputInspectionNumber(num){
				let _that = this
				if(_that.actualSample == -1){
					errorModal(_that,'提示信息','请先编辑存货明细子表的抽样数量',()=>{
						_that.$refs.autoform.clear('title4', 'inspectionNumber');
					})
				}else{
					if(Number(num) > Number(_that.actualSample)){
						errorModal(_that,'提示信息','检验数量不能大于货明细子表的抽样数量',()=>{
							_that.$refs.autoform.clear('title4', 'inspectionNumber');
						})
					}
				}
			},
			inputUnqualifiedNumber(num){
				let _that = this
				if(Number(num) > Number(_that.$refs.autoform.formdata.inspectionNumber)){
					errorModal(_that,'提示信息','不合格数量不能大于检验数量',()=>{
						_that.$refs.autoform.clear('title4', 'unqualifiedNumber');
					})
				}
			},
			onselectSample1ResultId(item){
				let _that = this
				_that.$refs.autoform.formdata.sample1ResultId = item.id
				_that.$refs.autoform.formdata.sample1ResultName = item.dicname
				if(item.id == '6226'){
					_that.$refs.autoform.formdata.sample1UnqualifiedTypeId = _that.$refs.autoform.formdata.nonConformanceCategoryId
					_that.$refs.autoform.formdata.sample1UnqualifiedTypeName = _that.$refs.autoform.formdata.nonConformanceCategoryName
				}else{
					_that.$refs.autoform.clear('title4', 'sample1UnqualifiedTypeId');
				}
			},
			onselectSample2ResultId(item){
				let _that = this
				_that.$refs.autoform.formdata.sample2ResultId = item.id
				_that.$refs.autoform.formdata.sample2ResultName = item.dicname
				if(item.id == '6226'){
					_that.$refs.autoform.formdata.sample2UnqualifiedTypeId = _that.$refs.autoform.formdata.nonConformanceCategoryId
					_that.$refs.autoform.formdata.sample2UnqualifiedTypeName = _that.$refs.autoform.formdata.nonConformanceCategoryName
				}else{
					_that.$refs.autoform.clear('title4', 'sample2UnqualifiedTypeId');
				}
			},
			onselectSample3ResultId(item){
				let _that = this
				_that.$refs.autoform.formdata.sample3ResultId = item.id
				_that.$refs.autoform.formdata.sample3ResultName = item.dicname
				if(item.id == '6226'){
					_that.$refs.autoform.formdata.sample3UnqualifiedTypeId = _that.$refs.autoform.formdata.nonConformanceCategoryId
					_that.$refs.autoform.formdata.sample3UnqualifiedTypeName = _that.$refs.autoform.formdata.nonConformanceCategoryName
				}else{
					_that.$refs.autoform.clear('title4', 'sample3UnqualifiedTypeId');
				}
			},
			onselectSample4ResultId(item){
				let _that = this
				_that.$refs.autoform.formdata.sample4ResultId = item.id
				_that.$refs.autoform.formdata.sample4ResultName = item.dicname
				if(item.id == '6226'){
					_that.$refs.autoform.formdata.sample4UnqualifiedTypeId = _that.$refs.autoform.formdata.nonConformanceCategoryId
					_that.$refs.autoform.formdata.sample4UnqualifiedTypeName = _that.$refs.autoform.formdata.nonConformanceCategoryName
				}else{
					_that.$refs.autoform.clear('title4', 'sample4UnqualifiedTypeId');
				}
			},
			onselectSample5ResultId(item){
				let _that = this
				_that.$refs.autoform.formdata.sample5ResultId = item.id
				_that.$refs.autoform.formdata.sample5ResultName = item.dicname
				if(item.id == '6226'){
					_that.$refs.autoform.formdata.sample5UnqualifiedTypeId = _that.$refs.autoform.formdata.nonConformanceCategoryId
					_that.$refs.autoform.formdata.sample5UnqualifiedTypeName = _that.$refs.autoform.formdata.nonConformanceCategoryName
				}else{
					_that.$refs.autoform.clear('title4', 'sample5UnqualifiedTypeId');
				}
			}
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				
			}
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
				if(e.actualSample){
					_that.actualSample = e.actualSample
				}
			if(e.configDataCacheKey){
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							
							

							_that.initLoad()
							
							}
						}
					})
				}
			})
		}
	}
</script>

<style>
</style>                                                                                                                                                                                                                                                                                                                                                                                                                                                         
                                            